﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using ShadowCommando.Game.Elements;
using ShadowCommando.Game.Elements.Bulllets;
using ShadowCommando.Game.GameSounds;
namespace ShadowCommando.Game.Utilites
{
    /// <summary>
    /// Broń 
    /// </summary>
   public class Weapon
    {
       /// <summary>
       /// Konstruktor
       /// </summary>
       /// <param name="_step">Krok </param>
       /// <param name="_bulletId">Id pocisku</param>
       /// <param name="_owner">Owner</param>
       /// <param name="_difficulty">Poziom trudności</param>
        public Weapon(int _step,BulletId _bulletId,ElementId _owner,LevelDifficulty _difficulty)
        {
            step = _step;
            bulletId = _bulletId;
            owner = _owner;
            difficulty = _difficulty;
            bullet=CreateBullet();
           switch (_bulletId)
           {
               case BulletId.Laser:
                   {
                       bulletCount = UtilitesSettings.Default.MaxLaser;
                       break;
                   }
               case Elements.BulletId.HeavyLaser:
                   {
                       bulletCount = UtilitesSettings.Default.MaxHeavyLaser;
                       break;
                   }
               case Elements.BulletId.Flechette:
                   {
                       bulletCount = UtilitesSettings.Default.MaxFlechette;
                       break;
                   }
               case Elements.BulletId.Bomb:
                   {
                       bulletCount = UtilitesSettings.Default.MaxBomb;
                       break;
                   }
                   default:
                   {
                       bulletCount = 1;
                       break;
                   }
           }
           maxBullet = bulletCount;
            soundId = bullet.SoundId;
        }
        #region Elements

       private Bullet bullet;
       private SoundID soundId;
       private LevelDifficulty difficulty;
        private int step;
        private BulletId bulletId;
        private int bulletCount;
        private ElementId owner;

        #endregion
        private int maxBullet;
        #region Properties
       /// <summary>
       /// SoundId
       /// </summary>
       public SoundID SoundId
       {
           get { return soundId; }
           set { soundId = value; }
       }
       /// <summary>
       /// Poziom trudności
       /// </summary>
        public LevelDifficulty Difficulty
        {
            get { return difficulty; }
            set { difficulty = value; }
        }
       /// <summary>
       /// Maxymalna ilość pocisków
       /// </summary>
       public int MaxBullet
       {
           get { return maxBullet; }
           set { maxBullet = value; }
       }
       /// <summary>
       /// Id pocisku
       /// </summary>
        public BulletId BulletId
        {
            get
            {
                return bulletId;
            }
        }
       /// <summary>
       /// Zasięg pocisku
       /// </summary>
       public int Distance
        {
            get { return bullet.Distance; }
        }
       /// <summary>
       /// Aktualna ilość pocisków
       /// </summary>
        public int BulletCount
        {
            get
            {
                return bulletCount;
            }
            set
            {
                bulletCount = value;
            }
        }
        #endregion

        private Bullet CreateBullet()
        {

            return new Bullet(step,difficulty, owner,bulletId);
        }
        private int[] ReadInfo(string str)
        {
            List<int> list = new List<int>();
            string[] splits = str.Split(new char[] { '|' });
            foreach (string s in splits)
            {
                if (s == "")
                    continue;

                list.Add((int.Parse(s)));
            }
            return list.ToArray();
        }
        /// <summary>
        /// Strzelaj
        /// </summary>
        /// <param name="p1">Cel</param>
        /// <param name="_fakeLocation">"Fakowy" pkt </param>
        /// <param name="_cos">Cos kąta pocisku</param>
        /// <param name="_sin">Sin kąta pocisku</param>
        /// <returns>Pocisk</returns>
       public Bullet Shot(Point p1,Point _fakeLocation,double  _cos,double _sin)
        {
            if(bulletCount!=0)
            {
                Bullet bullet = CreateBullet();
                bullet.FakeLocation = _fakeLocation;
                bullet.SetStraight(p1,_cos,_sin);
                return bullet;
            }
            return null;

        }
    }
}
